﻿using Axiom.CodeManifold;
using Axiom.CodeManifold.WPF.ViewModels;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Axiom.CodeManifold.WPF.SampleData
{
	public class ServiceManifoldSampleData : ServiceManifoldViewModel
    {
        public ServiceManifoldSampleData()
        {
            var services = new List<ServiceDefinition>();
            using (Stream fs = this.GetType().Assembly.GetManifestResourceStream(@"Axiom.CodeManifold.WPF.SampleData.sample-data.xml"))
            {
                var xs = new XmlSerializer(typeof(List<ServiceDefinition>));
                services = xs.Deserialize(fs) as List<ServiceDefinition>;
            }

            services.Sort((a, b) => { return a.Name.CompareTo(b.Name); });

            ServiceInterfaces.Clear();

            foreach (var service in services)
            {
                ServiceInterfaces.Add(service);
            }

			var methods = new List<MethodDefinition>();
			foreach (var service in services)
			{
				ServiceInterfaces.Add(service);
				methods.AddRange(service.Methods);
			}

			ServiceMethods.Clear();
			methods.Sort((a, b) => a.Name.CompareTo(b.Name));
			foreach (var method in methods)
			{
				ServiceMethods.Add(method);
			}

            SelectedServiceInterface = ServiceInterfaces.First();
			SelectedServiceMethod = SelectedServiceInterface.Methods.First();

			NewMethodName = "GetSomeThingFromTheDatabase";

            IsBusy = true;
            SvcImplementationProject = true;
            Status = "System Ready";
        }

        public override async void Refresh()
		{
            await Task.Run(() => { });
		}
	}
}
